function init() {}

function setup(b, a) {
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    var b = em.newInstance("Yzc");
    b.setProperty("pigcount", 0);
    b.setProperty("rabbits", 0);
    b.setProperty("times", 0);
    var d = b.setInstanceMap(866010454);
    d.resetFully();
    b.getMapInstance(866010454).killAllMonsters(false);
    var c = em.getMonster(9302000);
    c.setOverrideStats();
    c.getChangedStats().hp = 30000000;
    c.heal();
    d.spawnMonsterOnGroundBelow(c, new java.awt.Point(0, 82));
    spawnMonster(b);
    d.spawnNpc(9300006, new java.awt.Point(670, 82));
    b.startEventTimer(1000 * 60 * 10);
    return b
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(0);
    c.startMapEffect("一定要好好保护金猪！如果不小心杀死了金猪，任务就失败了！", 5120026);
    a.changeMap(c, c.getPortal(0))
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(c, b, a) {
    if (a != 866010454) {
        c.unregisterPlayer(b);
        if (c.disposeIfPlayerBelow(0, 0)) {
            em.setProperty("state", "0");
            em.setProperty("leader", "true")
        }
        return
    }
}

function spawnMonster(c) {
    var e = c.getMapInstance(0);
    var d = null;
    var f = Array(-700, -550, -400, -250, -100, 50, 200, 350, 500, 650);
    overrideStats.setHp(hprand);
    for (var b = 0; b < 10; b++) {
        d = em.getMonster(5250003);
        d.setOverrideStats();
        d.getChangedStats().hp = 3000000;
        d.heal();
        var a = f[b];
        e.spawnMonsterOnGroundBelow(d, new java.awt.Point(a, 82))
    }
}

function onPlayerDisconnected(b, a) {
    b.disposeIfPlayerBelow(100, 910000000);
    em.setProperty("state", "0");
    em.setProperty("leader", "true");
    return 0
}

function onMonsterKilled(b, d) {
    if (em.getProperty("state") == 1) {
        if (b.getMapInstance(0).getNumMonsters() == 1) {
            spawnMonster(b)
        }
        var c = 1 * b.getProperty("pigcount");
        c++;
        b.setProperty("pigcount", c);
        if (d == 9302000) {
            b.startEventTimer(1000 * 1);
            for (var a = 0; a < b.getPlayerCount(); a++) {
                b.getPlayers().get(a).dropMessage(1, "你打死了金猪，保卫金猪失败！");
                b.disposeIfPlayerBelow(100, 910000000)
            }
            return
        }
    }
    return 1
}

function playerExit(b, a) {
    b.unregisterPlayer(a);
    if (b.disposeIfPlayerBelow(0, 0)) {
        em.setProperty("state", "0");
        em.setProperty("leader", "true")
    }
}

function onTimeOut(a) {
    if (em.getProperty("state") != 2) {
        var b = a.getMapInstance(0);
        em.setProperty("state", "2");
        b.killAllMonsters(true);
        a.startEventTimer(1000 * 60 * 1);
        b.startMapEffect("恭喜你成功守卫了金猪，去找蒋老板领取额外的奖励吧！", 5120026);
        em.setProperty("leader", "true")
    } else {
        em.setProperty("state", "0");
        a.disposeIfPlayerBelow(100, 910000000)
    }
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {};